package logic

import (
	"context"
	"house_srv/models/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PersonHouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPersonHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PersonHouseListLogic {
	return &PersonHouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PersonHouseListLogic) PersonHouseList(in *house.PersonHouseListRequest) (*house.PersonHouseListResponse, error) {
	// todo: 房源列表接口
	var h []mysql.House

	mysql.Db.Model(&h).Where("user_id = ?", in.UserId).Order("house_status").Order("created_at desc").Limit(10).Find(&h)
	m := mysql.House{}
	err := m.HouseInfo()
	if err != nil {
		return nil, err
	}
	var slice []*house.PersonHouseList

	for _, v := range h {
		list := house.PersonHouseList{
			UserId:        v.UserId,
			HouseCity:     v.HouseCity,
			Address:       v.Address,
			HouseBuild:    v.HouseBuild,
			HouseFloor:    v.HouseFloor,
			HouseArea:     v.HouseArea,
			HousePrice:    float32(v.HousePrice),
			HouseDescribe: v.HouseDescribe,
			HouseCover:    v.HouseCover,
			HouseStatus:   v.HouseStatus,
		}
		slice = append(slice, &list)
	}
	return &house.PersonHouseListResponse{
		List: slice,
	}, nil
}
